$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'eys/edeviceold/list',
        datatype: "json",
        colModel: [			
			{ label: 'guid', name: 'guid', index: 'guid', width: 50, key: true },
			{ label: '所属项目ID', name: 'pGuid', index: 'p_guid', width: 80 }, 			
			{ label: '所属点位ID', name: 'pPGuid', index: 'p_p_guid', width: 80 }, 			
			{ label: '关联设备信息库ID', name: 'dDGuid', index: 'd_d_guid', width: 80 }, 			
			{ label: '工作类型', name: 'dRWork', index: 'd_r_work', width: 80 }, 			
			{ label: '设备大类', name: 'dRBigtype', index: 'd_r_bigtype', width: 80 }, 			
			{ label: '设备中类', name: 'dRMidtype', index: 'd_r_midtype', width: 80 }, 			
			{ label: '设备名称', name: 'dRName', index: 'd_r_name', width: 80 }, 			
			{ label: '主要参数', name: 'dRParameter', index: 'd_r_parameter', width: 80 }, 			
			{ label: '电压等级   数据字典 voltage_type(10kV,380V,220V)', name: 'dRVoltage', index: 'd_r_voltage', width: 80 }, 			
			{ label: '设备厂家', name: 'dRFactory', index: 'd_r_factory', width: 80 }, 			
			{ label: '出厂日期', name: 'dRFactorydate', index: 'd_r_factorydate', width: 80 }, 			
			{ label: '投运日期', name: 'dRDeliverydate', index: 'd_r_deliverydate', width: 80 }, 			
			{ label: '固定资产卡片编号', name: 'dRCode', index: 'd_r_code', width: 80 }, 			
			{ label: '资产原值（万元）', name: 'dRPrice', index: 'd_r_price', width: 80 }, 			
			{ label: '处置意见  数据字典 opinion_type', name: 'dROpinion', index: 'd_r_opinion', width: 80 }, 			
			{ label: '拟拆除日期', name: 'dRRemovedate', index: 'd_r_removedate', width: 80 }, 			
			{ label: ' 处置去向 数据字典where_type', name: 'dRWhere', index: 'd_r_where', width: 80 }, 			
			{ label: '资产净值（万元）', name: 'dRNetassets', index: 'd_r_netassets', width: 80 }, 			
			{ label: '资产净值（万元）', name: 'dRRate', index: 'd_r_rate', width: 80 }, 			
			{ label: '改造内容', name: 'dRReformcontent', index: 'd_r_reformcontent', width: 80 }, 			
			{ label: '技改费用', name: 'dRReformcost', index: 'd_r_reformcost', width: 80 }, 			
			{ label: '改造后参数', name: 'dRReformparameter', index: 'd_r_reformparameter', width: 80 }, 			
			{ label: '购置设备表guid', name: 'dRGuid', index: 'd_r_guid', width: 80 }, 			
			{ label: '数据状态', name: 'dRDatastate', index: 'd_r_datastate', width: 80 }, 			
			{ label: '设备标签', name: 'dLabel', index: 'd_label', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		eDeviceOld: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.eDeviceOld = {};
		},
		update: function (event) {
			var guid = getSelectedRow();
			if(guid == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(guid)
		},
		saveOrUpdate: function (event) {
			var url = vm.eDeviceOld.guid == null ? "eys/edeviceold/save" : "eys/edeviceold/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.eDeviceOld),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var guids = getSelectedRows();
			if(guids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "eys/edeviceold/delete",
                    contentType: "application/json",
				    data: JSON.stringify(guids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(guid){
			$.get(baseURL + "eys/edeviceold/info/"+guid, function(r){
                vm.eDeviceOld = r.eDeviceOld;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});